// 使用帮助函数 _average 重构 averageDollarValue，使用函数组合的方式实现
const { reduce, map, add, prop, flowRight } = require('lodash/fp')
const { cars } = require('./data')

let _average = function (xs) {
  return reduce(add, 0, xs) / xs.length
}

// let averageDollarValue = function (cars) {
//   let dollar_value = map(function(car) {
//     return car.dollar_value
//   }, cars)
//   return _average(dollar_value)
// }

// console.log(averageDollarValue(cars))

let averageDollarValue = flowRight(_average, map(prop('dollar_value')))
console.log(averageDollarValue(cars))
